import { LocalStorageKeys } from '~/enums/localstorage'
import { getItem,setItem } from '~/utils'
export default defineNuxtRouteMiddleware((to) => {
  if (process.server) return
  const nuxtApp = useNuxtApp()
  if (process.client && nuxtApp.isHydrating && nuxtApp.payload.serverRendered) {
    if ((to.path !== '/home' && to.path !== '/login') && !getItem('token')) {
      const id = getItem('pinpaiId')
      if(id == ''){
        const idClone = new URLSearchParams(window.location.search).get('id');
        const tenantId = new URLSearchParams(window.location.search).get('tenantId');
        setItem('pinpaiId', idClone)
        setItem('tenantId', tenantId)
        return window.location.href = `/home`
      }
      else{
        return window.location.href = '/home'
      }

    }
  }
})
